#!/usr/bin/evn python
# coding=utf-8
from typing import List, Dict

from peewee import fn

from infirmary_admin_src.infirmary_smart_admin.infirmary_models.admin_dbhelper import session_scope, \
    session_scope_atomic, JOIN
from infirmary_admin_src.infirmary_smart_admin.infirmary_models.admin_model import SysEmployee, SysMenu, \
    SysRoleEmployee, SysRole, SysDept


class DepartmentBusinesses:
    pass

    @classmethod
    def get_sys_dpartment_id_max_id(cls):
        '''
        添加职务
        :param role_id:
        :return:
        '''
        with session_scope():
            return SysDept.select(fn.MAX(SysDept.department_id)).scalar()

    @classmethod
    def del_sys_dpartment_by_id(cls, department_id):
        '''
        添加职务
        :param role_id:
        :return:
        '''
        with session_scope():
            return SysDept.delete().where(SysDept.department_id == department_id).execute()

    @staticmethod
    def get_sys_dpartment_info():
        with session_scope():
            def mack(v):
                v['managerName'] = 'XXXX'
                return v

            return [mack(v) for v in SysDept.select().dicts()]

    @staticmethod
    def get_sys_dpartment_info_by_name(name) -> SysEmployee:
        with session_scope():
            return SysDept.get_or_none(SysDept.name == name)

    @classmethod
    def add_sys_dpartment_info(cls, **kwargs):
        with session_scope():
            return SysDept.get_or_create(**kwargs)

    @classmethod
    def edit_sys_dpartment_info(cls, department_id, **kwargs):
        with session_scope():
            return SysDept.update(**kwargs).where(
                SysDept.department_id == department_id).execute()
